package commons.params.ihm;

import commons.utils.Utils;
import java.awt.Color;

public class DlgTestPattern extends javax.swing.JDialog {

    public DlgTestPattern() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        tf_Chaine = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tf_Pattern = new javax.swing.JTextField();
        btn_Tester = new javax.swing.JButton();
        tf_Result = new javax.swing.JTextField();
        btn_Quit = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Testeur de pattern");

        jLabel1.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        jLabel1.setText("Chaine à tester :");

        tf_Chaine.setFont(new java.awt.Font("Trebuchet MS", 0, 11));

        jLabel2.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        jLabel2.setText("Pattern :");

        tf_Pattern.setFont(new java.awt.Font("Trebuchet MS", 0, 11));

        btn_Tester.setFont(new java.awt.Font("Trebuchet MS", 0, 11));
        btn_Tester.setText("Tester");
        btn_Tester.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_TesterActionPerformed(evt);
            }
        });

        tf_Result.setFont(new java.awt.Font("Trebuchet MS", 0, 11));

        btn_Quit.setFont(new java.awt.Font("Trebuchet MS", 1, 11));
        btn_Quit.setText("QUITTER");
        btn_Quit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_QuitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_Result, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
                    .addComponent(tf_Pattern, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
                    .addComponent(tf_Chaine, javax.swing.GroupLayout.DEFAULT_SIZE, 341, Short.MAX_VALUE)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(btn_Tester)
                    .addComponent(btn_Quit))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tf_Chaine, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tf_Pattern, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btn_Tester)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tf_Result, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addComponent(btn_Quit)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void btn_QuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_QuitActionPerformed
		setVisible(false);
	}//GEN-LAST:event_btn_QuitActionPerformed

	private void btn_TesterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_TesterActionPerformed
		if (!Utils.isValidePattern(tf_Pattern.getText())) {
			tf_Result.setBackground(Color.RED);
			tf_Result.setForeground(Color.WHITE);
			tf_Result.setText("Le pattern est invalide");
			return;
		}

		tf_Result.setBackground(Color.WHITE);

		if (tf_Chaine.getText().matches(tf_Pattern.getText())) {
			tf_Result.setForeground(Color.GREEN.darker());
			tf_Result.setText("La chaine correspond au pattern");
		} else {
			tf_Result.setForeground(Color.RED);
			tf_Result.setText("La chaine NE correspond PAS au pattern");
		}
	}//GEN-LAST:event_btn_TesterActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Quit;
    private javax.swing.JButton btn_Tester;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField tf_Chaine;
    private javax.swing.JTextField tf_Pattern;
    private javax.swing.JTextField tf_Result;
    // End of variables declaration//GEN-END:variables

}
